package vip.xiaonuo.vehicle.vehicleTraffic.api;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.vehicle.vehicleTraffic.dto.HeartBeatDTO;
import vip.xiaonuo.vehicle.vehicleTraffic.dto.PlateResult;
import vip.xiaonuo.vehicle.vehicleTraffic.dto.PlateRuseltResponse;
import vip.xiaonuo.vehicle.vehicleTraffic.service.VehicleTrafficService;

import javax.annotation.Resource;

/**
 * 板外api控制器
 *
 * @author cad
 * @date 2023/02/22
 */
@RestController
@Slf4j
public class VehicleTrafficApi {

    @Resource
    private VehicleTrafficService iVehicleTrafficService;


    @PostMapping("/plate/heartBeat")
    public PlateRuseltResponse heartBeat( HeartBeatDTO heartBeatDTO) {
        log.info("收到车闸心跳参数【{}】", heartBeatDTO);
        iVehicleTrafficService.registerAndHeartBeat(heartBeatDTO);


        PlateRuseltResponse plateRuseltResponse = new PlateRuseltResponse();
        PlateRuseltResponse.ResponseAlarmInfoPlateDTO responseAlarmInfoPlateDTO =
                new PlateRuseltResponse.ResponseAlarmInfoPlateDTO();
        responseAlarmInfoPlateDTO.setInfo("false")
                .setChannelNum(0).setIsPay("false");
        plateRuseltResponse.setResponseAlarminfoplate(responseAlarmInfoPlateDTO);
        log.info("返回心跳结果【{}】", plateRuseltResponse);
        return plateRuseltResponse;
    }


    @PostMapping("/plate/in")
    public PlateRuseltResponse plateIn(@RequestBody PlateResult plateRuselt) {
        log.info("收到车闸识别请求参数【{}】", plateRuselt);
        PlateRuseltResponse plateRuseltResponse = new PlateRuseltResponse();
        PlateRuseltResponse.ResponseAlarmInfoPlateDTO responseAlarmInfoPlateDTO =
                new PlateRuseltResponse.ResponseAlarmInfoPlateDTO();
        Boolean aBoolean = iVehicleTrafficService.checkVehicleTraffic(plateRuselt);
        responseAlarmInfoPlateDTO.setInfo(aBoolean ? "ok" : "no")
                .setPlateid(plateRuselt.getAlarmInfoPlate().getResult().getPlateResult().getPlateid())
                .setChannelNum(0).setIsPay("true");
        plateRuseltResponse.setResponseAlarminfoplate(responseAlarmInfoPlateDTO);
        log.info("返回车闸结果【{}】", plateRuseltResponse);
        return plateRuseltResponse;
    }


}
